{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4e3a8ce8",
   "metadata": {},
   "source": [
    "# 1.requests(让HTTPS服务人类)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "85ee3b69",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:42:35.972855Z",
     "start_time": "2022-03-08T12:42:35.969639Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1399df59",
   "metadata": {},
   "source": [
    "* r是指 response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a4b32320",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:46:49.067058Z",
     "start_time": "2022-03-08T12:46:48.527234Z"
    }
   },
   "outputs": [],
   "source": [
    "r = requests.get(\"https://cn.bing.com/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a04b0d3",
   "metadata": {},
   "source": [
    "* r.content\n",
    "> 1.可以获取请求数据内容（观察页面数据形态 HTML，Json）\n",
    "> 2. b 是指 bytes：二进制文件\n",
    "* r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4c28dcb7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:47:25.062572Z",
     "start_time": "2022-03-08T12:47:24.422605Z"
    }
   },
   "outputs": [],
   "source": [
    "r = requests.get(\"http://httpbin.org/get\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1bd63341",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:48:17.636709Z",
     "start_time": "2022-03-08T12:48:17.619916Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'120.85.41.57'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()  #将json数据转换成字典  #['origin']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6456f18c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:48:18.531495Z",
     "start_time": "2022-03-08T12:48:18.520398Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\\n  \"args\": {}, \\n  \"headers\": {\\n    \"Accept\": \"*/*\", \\n    \"Accept-Encoding\": \"gzip, deflate\", \\n    \"Host\": \"httpbin.org\", \\n    \"User-Agent\": \"python-requests/2.25.1\", \\n    \"X-Amzn-Trace-Id\": \"Root=1-6227505c-6239511324214a0e1dba6836\"\\n  }, \\n  \"origin\": \"120.85.41.57\", \\n  \"url\": \"http://httpbin.org/get\"\\n}\\n'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51e73650",
   "metadata": {},
   "source": [
    "* 3. payload\n",
    "> 使用payload是、来实现请求数据传递"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "17997474",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:51:56.854266Z",
     "start_time": "2022-03-08T12:51:55.742305Z"
    }
   },
   "outputs": [],
   "source": [
    "payload = {\n",
    "    'name':'zhichao',\n",
    "    'JOB':'IT'\n",
    "    \n",
    "}\n",
    "r = requests.get(\"https://httpbin.org/get\",params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "88cfa0ad",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:52:01.214786Z",
     "start_time": "2022-03-08T12:52:01.208658Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0d5d11f7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:52:37.300305Z",
     "start_time": "2022-03-08T12:52:37.280964Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'args': {'JOB': 'IT', 'name': 'zhichao'},\n",
       " 'headers': {'Accept': '*/*',\n",
       "  'Accept-Encoding': 'gzip, deflate',\n",
       "  'Host': 'httpbin.org',\n",
       "  'User-Agent': 'python-requests/2.25.1',\n",
       "  'X-Amzn-Trace-Id': 'Root=1-6227516c-6642a92c7778a0d32722bf05'},\n",
       " 'origin': '120.85.41.57',\n",
       " 'url': 'https://httpbin.org/get?name=zhichao&JOB=IT'}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b33d9eb2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T12:56:22.459231Z",
     "start_time": "2022-03-08T12:56:22.453893Z"
    }
   },
   "source": [
    "# 2. face++ detect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7eb7dd42",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T13:12:24.752280Z",
     "start_time": "2022-03-08T13:12:23.542431Z"
    }
   },
   "outputs": [],
   "source": [
    " # 1.准备base url（对应该功能的url链接）\n",
    "face_detect_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "# 2.准备参数数据\n",
    "payload = {\n",
    "    'api_key':'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF',\n",
    "    'api_secret':'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1',\n",
    "    'image_url':'https://tse4-mm.cn.bing.net/th/id/OIP-C.AzDZGug1zMS_9bRE7IuyVAHaHa?w=220&h=220&c=7&r=0&o=5&dpr=1.25&pid=1.7',\n",
    "    'return_landmark':1,\n",
    "    'return_attributes':'gender,age,smiling,emotion'\n",
    "}\n",
    "\n",
    "# 3.检查调用的请求方法：POST\n",
    "# 4.请求人脸数据\n",
    "r = requests.post(url = face_detect_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "072788c1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T13:12:25.490459Z",
     "start_time": "2022-03-08T13:12:25.476937Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "54d31241",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-08T13:12:26.542282Z",
     "start_time": "2022-03-08T13:12:26.526539Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1646745143,990ec081-942a-4594-a023-c5434020c2fb',\n",
       " 'time_used': 872,\n",
       " 'faces': [{'face_token': '4b945317c024be471f4cfa0a0e5318cb',\n",
       "   'face_rectangle': {'top': 99, 'left': 68, 'width': 145, 'height': 145},\n",
       "   'landmark': {'contour_chin': {'x': 139, 'y': 236},\n",
       "    'contour_left1': {'x': 67, 'y': 132},\n",
       "    'contour_left2': {'x': 69, 'y': 148},\n",
       "    'contour_left3': {'x': 71, 'y': 162},\n",
       "    'contour_left4': {'x': 74, 'y': 177},\n",
       "    'contour_left5': {'x': 79, 'y': 191},\n",
       "    'contour_left6': {'x': 86, 'y': 204},\n",
       "    'contour_left7': {'x': 96, 'y': 216},\n",
       "    'contour_left8': {'x': 108, 'y': 225},\n",
       "    'contour_left9': {'x': 122, 'y': 233},\n",
       "    'contour_right1': {'x': 212, 'y': 129},\n",
       "    'contour_right2': {'x': 211, 'y': 144},\n",
       "    'contour_right3': {'x': 210, 'y': 159},\n",
       "    'contour_right4': {'x': 207, 'y': 174},\n",
       "    'contour_right5': {'x': 203, 'y': 189},\n",
       "    'contour_right6': {'x': 196, 'y': 202},\n",
       "    'contour_right7': {'x': 185, 'y': 214},\n",
       "    'contour_right8': {'x': 172, 'y': 224},\n",
       "    'contour_right9': {'x': 157, 'y': 232},\n",
       "    'left_eye_bottom': {'x': 101, 'y': 136},\n",
       "    'left_eye_center': {'x': 102, 'y': 130},\n",
       "    'left_eye_left_corner': {'x': 88, 'y': 129},\n",
       "    'left_eye_lower_left_quarter': {'x': 93, 'y': 133},\n",
       "    'left_eye_lower_right_quarter': {'x': 110, 'y': 134},\n",
       "    'left_eye_pupil': {'x': 103, 'y': 128},\n",
       "    'left_eye_right_corner': {'x': 118, 'y': 132},\n",
       "    'left_eye_top': {'x': 102, 'y': 122},\n",
       "    'left_eye_upper_left_quarter': {'x': 94, 'y': 124},\n",
       "    'left_eye_upper_right_quarter': {'x': 111, 'y': 125},\n",
       "    'left_eyebrow_left_corner': {'x': 75, 'y': 114},\n",
       "    'left_eyebrow_lower_left_quarter': {'x': 85, 'y': 113},\n",
       "    'left_eyebrow_lower_middle': {'x': 96, 'y': 114},\n",
       "    'left_eyebrow_lower_right_quarter': {'x': 107, 'y': 115},\n",
       "    'left_eyebrow_right_corner': {'x': 118, 'y': 114},\n",
       "    'left_eyebrow_upper_left_quarter': {'x': 84, 'y': 108},\n",
       "    'left_eyebrow_upper_middle': {'x': 96, 'y': 107},\n",
       "    'left_eyebrow_upper_right_quarter': {'x': 107, 'y': 108},\n",
       "    'mouth_left_corner': {'x': 113, 'y': 196},\n",
       "    'mouth_lower_lip_bottom': {'x': 135, 'y': 206},\n",
       "    'mouth_lower_lip_left_contour1': {'x': 124, 'y': 196},\n",
       "    'mouth_lower_lip_left_contour2': {'x': 119, 'y': 201},\n",
       "    'mouth_lower_lip_left_contour3': {'x': 126, 'y': 204},\n",
       "    'mouth_lower_lip_right_contour1': {'x': 148, 'y': 196},\n",
       "    'mouth_lower_lip_right_contour2': {'x': 154, 'y': 200},\n",
       "    'mouth_lower_lip_right_contour3': {'x': 146, 'y': 204},\n",
       "    'mouth_lower_lip_top': {'x': 135, 'y': 197},\n",
       "    'mouth_right_corner': {'x': 162, 'y': 195},\n",
       "    'mouth_upper_lip_bottom': {'x': 135, 'y': 196},\n",
       "    'mouth_upper_lip_left_contour1': {'x': 129, 'y': 189},\n",
       "    'mouth_upper_lip_left_contour2': {'x': 121, 'y': 192},\n",
       "    'mouth_upper_lip_left_contour3': {'x': 124, 'y': 196},\n",
       "    'mouth_upper_lip_right_contour1': {'x': 141, 'y': 189},\n",
       "    'mouth_upper_lip_right_contour2': {'x': 151, 'y': 192},\n",
       "    'mouth_upper_lip_right_contour3': {'x': 148, 'y': 195},\n",
       "    'mouth_upper_lip_top': {'x': 135, 'y': 190},\n",
       "    'nose_contour_left1': {'x': 124, 'y': 133},\n",
       "    'nose_contour_left2': {'x': 119, 'y': 158},\n",
       "    'nose_contour_left3': {'x': 125, 'y': 172},\n",
       "    'nose_contour_lower_middle': {'x': 135, 'y': 175},\n",
       "    'nose_contour_right1': {'x': 146, 'y': 133},\n",
       "    'nose_contour_right2': {'x': 151, 'y': 158},\n",
       "    'nose_contour_right3': {'x': 146, 'y': 172},\n",
       "    'nose_left': {'x': 115, 'y': 169},\n",
       "    'nose_right': {'x': 156, 'y': 169},\n",
       "    'nose_tip': {'x': 135, 'y': 163},\n",
       "    'right_eye_bottom': {'x': 173, 'y': 135},\n",
       "    'right_eye_center': {'x': 172, 'y': 129},\n",
       "    'right_eye_left_corner': {'x': 155, 'y': 132},\n",
       "    'right_eye_lower_left_quarter': {'x': 164, 'y': 134},\n",
       "    'right_eye_lower_right_quarter': {'x': 182, 'y': 132},\n",
       "    'right_eye_pupil': {'x': 171, 'y': 127},\n",
       "    'right_eye_right_corner': {'x': 188, 'y': 128},\n",
       "    'right_eye_top': {'x': 172, 'y': 121},\n",
       "    'right_eye_upper_left_quarter': {'x': 162, 'y': 125},\n",
       "    'right_eye_upper_right_quarter': {'x': 181, 'y': 123},\n",
       "    'right_eyebrow_left_corner': {'x': 153, 'y': 117},\n",
       "    'right_eyebrow_lower_left_quarter': {'x': 165, 'y': 116},\n",
       "    'right_eyebrow_lower_middle': {'x': 177, 'y': 114},\n",
       "    'right_eyebrow_lower_right_quarter': {'x': 188, 'y': 113},\n",
       "    'right_eyebrow_right_corner': {'x': 200, 'y': 114},\n",
       "    'right_eyebrow_upper_left_quarter': {'x': 164, 'y': 110},\n",
       "    'right_eyebrow_upper_middle': {'x': 176, 'y': 107},\n",
       "    'right_eyebrow_upper_right_quarter': {'x': 189, 'y': 108}},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 18},\n",
       "    'smile': {'value': 0.011, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.036,\n",
       "     'disgust': 0.0,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 0.001,\n",
       "     'neutral': 99.952,\n",
       "     'sadness': 0.001,\n",
       "     'surprise': 0.008}}}],\n",
       " 'image_id': 'dP/JrkzBDMyy8I4npImmtA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54c564d9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
